﻿using First.DAL;
using First.Model;

namespace First.BLL
{
    public class StudentBLL
    {
        StudentDAL studentdal = new StudentDAL();
        /// <summary>
        /// 获取学生信息
        /// </summary>
        /// <returns></returns>
        public Layui GetJsonStudentDetail()
        {
            Layui layui = new Layui();
            layui.code = 0;
            layui.count = studentdal.GetStudentDetails().Count;
            layui.msg = "";
            layui.data = studentdal.GetStudentDetails();
            return layui;
        }

        /// <summary>
        /// 删除学生信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Layui DelJsonStudent(int id)
        {
            if (studentdal.ResultSingleStudent(id) == null)
            {
                return null;
            }
            else
            {
                studentdal.DelStudent(id);
                return GetJsonStudentDetail();
            }

        }

        /// <summary>
        /// 添加、修改学生信息
        /// </summary>
        /// <param name="student"></param>
        /// <returns></returns>
        public Layui EditJsonStudent(Student student)
        {
            if (student.id == 0)
            {
                studentdal.AddStudent(student);
            }
            else
            {
                if (studentdal.ResultSingleStudent(student.id) == null)
                {
                    return null;
                }
                else
                {
                    studentdal.EditStudent(student);
                }
            }
            return GetJsonStudentDetail();
        }
    }
}
